package com.t282.crm.service;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;

@Service("redisService")
public class RedisService {
    @Resource
    private RedisTemplate redisTemplate;

    public boolean set(final String key,Object value){
        boolean result = false;
        try {
            ValueOperations<Serializable,Object> operations = redisTemplate.opsForValue();
            operations.set(key,value);
            result = true;
        }catch (Exception e){
            e.printStackTrace();
        }
        return  result;
    }

    public String get(String key){
        String value = null;
        try {
            ValueOperations<Serializable,Object> operations = redisTemplate.opsForValue();
            value = operations.get(key).toString();
        }catch (Exception e){
            e.printStackTrace();
        }
        return value;
    }
}
